package com.fengwk.resource.controller;

import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fengwk.resource.service.DownloadService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "下载")
@RestController
@RequestMapping("/api/download")
public class DownloadController {

	@Autowired
	private DownloadService downloadService;

	@ApiOperation(
			value = "单文件下载",
			response = Void.class)
	@RequestMapping(value = "/single", method = {RequestMethod.GET, RequestMethod.POST})
	public void single(
			@ApiParam(value = "文件id", required = true) @RequestParam(value = "fileId") Long fileId,
			@ApiParam(value = "文件名称", required = false) @RequestParam(value = "fileName", required = false) String fileName) {
		downloadService.single(fileId, fileName);
	}

	@ApiOperation(
			value = "打包下载",
			response = Void.class)
	@RequestMapping(value = "/package", method = {RequestMethod.GET, RequestMethod.POST})
	public void packages(
			@ApiParam(value = "文件id列表", required = true) @RequestParam(value = "fileIds") Collection<Long> fileIds,
			@ApiParam(value = "文件名称", required = false) @RequestParam(value = "fileName", required = false) String fileName) {
		downloadService.packages(fileIds, fileName);
	}

}
